package com.wenli.graduate2022.wenliGreenShop.entity;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.AccessLevel;
import lombok.Data;
import lombok.Getter;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Locale;

/**这是订单表，一个订单表对应多个产品订单（一个订单号里对应多个产品订单）。每个产品的购买都会产生一个产品订单
 * @author HuangHai
 * @date 2021/10/13 10:01
 */
@Data
@JsonIgnoreProperties(value = {"hibernateLazyInitializer", "handler" })
public class ProductOrder implements Serializable {
    private Integer productorderId;
    private String productorderCode;  //订单号
    private Address productOrderAddress;   //地址
    private String productorderDetailAddress;  //详细地址
    private String productorderPost;    //邮政编码
    private String productorderReceiver;      //收货人姓名
    private String productorderMobile;      //联系号码
    @Getter(AccessLevel.NONE)
    private Date productorderPayDate;       //支付日期
    @Getter(AccessLevel.NONE)
    private Date productorderDeliveryDate;      //发货日期
    @Getter(AccessLevel.NONE)
    private Date productorderConfirmDate;     //收货日期
    private Byte productorderStatus;      //订单状态：0：代付款，1：代发货，2：待收货，3：交易成功，4：交易关闭
    private User productOrderUser;        //关联用户
    private List<ProductOrderItem> productOrderItemList;  //该订单里包含的产品订单集合-----------  一对多

    public String getProductorderPayDate() {
        if (productorderPayDate != null) {
            SimpleDateFormat time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.UK);
            return time.format(productorderPayDate);
        }
        return null;
    }

    public String getProductorderDeliveryDate() {
        if (productorderDeliveryDate != null) {
            SimpleDateFormat time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.UK);
            return time.format(productorderDeliveryDate);
        }
        return null;
    }

    public String getProductorderConfirmDate() {
        if (productorderConfirmDate != null) {
            SimpleDateFormat time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.UK);
            return time.format(productorderConfirmDate);
        }
        return null;
    }
}
